package com.hdcx.Minfresh.adapter;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hdcx.Minfresh.R;
import com.hdcx.Minfresh.activity.BaseActivity;
import com.hdcx.Minfresh.activity.PointChangeActivity;
import com.hdcx.Minfresh.model.DiYongQuan;

/**
 * Created by Administrator on 2016/11/9.
 */

public class ChangePointAdapter extends RecyclerView.Adapter<ChangePointAdapter.GoodListHolder> {
    BaseActivity mActivity;
    DiYongQuan data;

    public ChangePointAdapter(Context context) {
        mActivity = (PointChangeActivity) context;
    }


    @Override
    public GoodListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
        LayoutInflater layoutInflater = LayoutInflater.from(mActivity);
        view = layoutInflater.inflate(R.layout.item_diyongquan, parent, false);

        return new GoodListHolder(view);
    }

    @Override
    public void onBindViewHolder(GoodListHolder holder, final int position) {
        if (holder instanceof GoodListHolder) {
            GoodListHolder goodListHolder = (GoodListHolder) holder;
//            goodListHolder.tv_title.setText(data.getList().get(position).getTitle());
//            if(data.getList().get(position).getInventory_show().equals("0")){
//                goodListHolder.tv_count.setVisibility(View.GONE);
//            }else{
//                goodListHolder.tv_count.setText("仅剩"+data.getList().get(position).getQuantity()+data.getList().get(position).getUnits());
//            }
//            holder.tv_status.setText(data.getList().get(position).getTxt());
//            String temp =data.getList().get(position).getScore()+"/"+data.getList().get(position).getUnits();
//            SpannableString styledText = new SpannableString(temp);
//            styledText.setSpan(new TextAppearanceSpan(mActivity, R.style.tv_red), 0,temp.length()-2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//            styledText.setSpan(new TextAppearanceSpan(mActivity, R.style.tv_size_25),0, data.getList().get(position).getScore().length()+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//            styledText.setSpan(new TextAppearanceSpan(mActivity, R.style.tv_size_13), temp.length()-2, temp.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//            goodListHolder.tv_money.setText(styledText, TextView.BufferType.SPANNABLE);
//           // goodListHolder.tv_money.setText("￥"+data.getList().get(position).getPrice()+"/"+data.getList().get(position).getUnits());
//            ImageLoader imageLoader = ImageLoader.getInstance();
//            DisplayImageOptions options = AppUtil.getNormalImageOptions();
//            imageLoader.displayImage(data.getList().get(position).getPic(),goodListHolder.img_main,options);
//
//            ((GoodListHolder) holder).layout_all.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    if(data.getList().get(position).getIs_use()==0){
//                        Toast.makeText(mActivity,"积分不足！",Toast.LENGTH_SHORT).show();
//                    }else{
//                        mActivity.onMyItemClick(data.getList().get(position).getId());
//                    }
//                }
//            });
        }
    }


    @Override
    public int getItemCount() {
        if (data == null || data.getList() == null) {
            return 0;
        }
//        return data.getList().size();
        return 6;
    }

    public void setData(DiYongQuan response) {
        data = response;
        notifyDataSetChanged();
    }

    public class GoodListHolder extends RecyclerView.ViewHolder {
        public LinearLayout layout_all;
        public TextView tv_money, tv_count, tv_title, tv_status;
        public ImageView img_main;

        public GoodListHolder(View itemView) {
            super(itemView);
            layout_all = (LinearLayout) itemView.findViewById(R.id.layout_all);
            img_main = (ImageView) itemView.findViewById(R.id.img_main);
            tv_money = (TextView) itemView.findViewById(R.id.tv_money);
            tv_count = (TextView) itemView.findViewById(R.id.tv_count);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title);
            tv_status = (TextView) itemView.findViewById(R.id.tv_status);
        }
    }
}
